package com.woniuxy.kaer.service.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.kaer.commons.util.Result;
import com.woniuxy.kaer.service.entity.ServiceProject;
import com.woniuxy.kaer.service.from.AddServiceProjectFrom;
import com.woniuxy.kaer.service.param.AddServiceProjectParam;
import com.woniuxy.kaer.service.service.ServiceProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 程诗洋
 * @since 2025年2月17日
 */
@RestController
@RequestMapping("/serviceProject")
@Api(tags = "服务项目类")
public class ServiceProjectController {
    @Resource
    private ServiceProjectService serviceProjectService;
    @PostMapping("/addServiceProject")
    @ApiOperation("新增服务项目接口")
    public Result addServiceProjectList(@RequestBody AddServiceProjectFrom from)throws Exception{
        AddServiceProjectParam addServiceProjectParam = BeanUtil.toBean(from, AddServiceProjectParam.class);
        serviceProjectService.addServiceProject(addServiceProjectParam);
        return Result.succeed("新增服务项目成功",null);
    }
    //通过服务类别Id查询服务项目
    @GetMapping("/getServiceProjectByServiceBaseId")
    @ApiOperation("通过服务类别Id查询服务项目接口")
    public Result getServiceProjectByServiceBaseId(@RequestParam("serviceBaseId") Integer serviceBaseId)throws Exception{
        List<ServiceProject> serviceProjects =serviceProjectService.getServiceProjectByServiceBaseId(serviceBaseId);
        return Result.succeed("通过服务类别Id查询服务项目成功",serviceProjects);
    }
    //删除服务项目
    @DeleteMapping("/deleteServiceProject")
    @ApiOperation("删除服务项目接口")
    public Result deleteServiceProject( Integer serviceProjectId)throws Exception{
        serviceProjectService.removeServiceProjectById(serviceProjectId);
        return Result.succeed("删除服务项目成功",null);
    }
}

